/**
* 防抖操作（防止多次使用）
* func: 函数
* delay: 延迟事件
*/
export function debounce(func, delay = 20) {
  let timer = null;
  return function (...args) {
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      func.apply(this, args)
    }, delay)
  }
}

export function formatDate(time = 1535697272, fmt = '-') {
  let date = new Date(time);
  let YY = date.getFullYear();
  let MM = String(date.getMonth() + 1).padStart(2, '0');
  let DD = String(date.getDate()).padStart(2, '0');
  let hh = String(date.getHours()).padStart(2, '0');
  let mm = String(date.getMinutes()).padStart(2, '0');
  let ss = String(date.getSeconds()).padStart(2, '0');
  return `${YY}${fmt}${MM}${fmt}${DD} ${hh}:${mm}:${ss}`;
}

/**
 * formatDate(date, 'yyyy-MM-dd hh:mm:ss)
export function formatDate(date, fmt) {
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
  }
  let o = {
    'M+': date.getMonth() + 1,
    'd+': date.getDate(),
    'h+': date.getHours(),
    'm+': date.getMinutes(),
    's+': date.getSeconds()
  };
  for (let k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      let str = o[k] + '';
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
    }
  }
  return fmt;
};
*/
